package legumes.shared.domain;

import java.io.Serializable;

import javax.persistence.Id;

import com.googlecode.objectify.annotation.Serialized;

public class Product implements Serializable, Comparable<Product> {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id private String name;
	@Serialized private ProductVariety productVariety;

	
	@Override
	public String toString() {

		return getName();
	}

	@Override
	public boolean equals(Object obj_) {
		return getName().equals(((Product) obj_).getName());
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ProductVariety getProductVariety() {
		return productVariety;
	}

	public void setProductVariety(ProductVariety productVariety) {
		this.productVariety = productVariety;
	}

	@Override
	public int compareTo(Product p_) {
		if( p_.getProductVariety().getProductCategory().getName().equalsIgnoreCase(this.getProductVariety().getProductCategory().getName())){
			if(p_.getProductVariety().getName().equalsIgnoreCase(this.getProductVariety().getName())){
				return p_.getName().compareTo(this.getName());
			} else {
				return p_.getProductVariety().getName().compareTo(this.getProductVariety().getName());
			}
		} else {
			return p_.getProductVariety().getProductCategory().getName().compareTo(this.getProductVariety().getProductCategory().getName());
		}
	}
	
	
}
